{% extends "base.html" %}

{% block title %}用户列表 - 妙趣拾光锦盒管理系统{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12 d-flex justify-content-between align-items-center">
        <h2 class="mb-0"><i class="fas fa-users me-2"></i>用户列表</h2>
        <a href="{{ url_for('user.add') }}" class="btn btn-primary">
            <i class="fas fa-user-plus me-1"></i>添加用户
        </a>
    </div>
</div>

<!-- 筛选器 -->
<div class="card mb-4 shadow-sm">
    <div class="card-header bg-light">
        <h5 class="mb-0"><i class="fas fa-filter me-2"></i>筛选条件</h5>
    </div>
    <div class="card-body">
        <form method="GET" action="{{ url_for('user.list') }}">
            <div class="row">
                <div class="col-md-3 mb-2">
                    <label for="username" class="form-label">用户名</label>
                    <input type="text" class="form-control" id="username" name="username" value="{{ request.args.get('username', '') }}">
                </div>
                <div class="col-md-3 mb-2">
                    <label for="email" class="form-label">邮箱</label>
                    <input type="text" class="form-control" id="email" name="email" value="{{ request.args.get('email', '') }}">
                </div>
                <div class="col-md-3 mb-2">
                    <label for="phone" class="form-label">电话</label>
                    <input type="text" class="form-control" id="phone" name="phone" value="{{ request.args.get('phone', '') }}">
                </div>
                <div class="col-md-3 mb-2">
                    <label for="is_admin" class="form-label">用户类型</label>
                    <select class="form-select" id="is_admin" name="is_admin">
                        <option value="">全部用户</option>
                        <option value="1" {% if request.args.get('is_admin') == '1' %}selected{% endif %}>管理员</option>
                        <option value="0" {% if request.args.get('is_admin') == '0' %}selected{% endif %}>普通用户</option>
                    </select>
                </div>
            </div>
            <div class="d-flex justify-content-end mt-3">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-search me-1"></i>查询
                </button>
                <a href="{{ url_for('user.list') }}" class="btn btn-secondary ms-2">
                    <i class="fas fa-redo me-1"></i>重置
                </a>
            </div>
        </form>
    </div>
</div>

<!-- 用户列表 -->
<div class="card shadow-sm">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover table-sortable">
                <thead>
                    <tr>
                        <th data-sort="id" scope="col">#</th>
                        <th data-sort="username" scope="col">用户名</th>
                        <th data-sort="name" scope="col">姓名</th>
                        <th data-sort="email" scope="col">邮箱</th>
                        <th data-sort="phone" scope="col">电话</th>
                        <th data-sort="date" scope="col">注册时间</th>
                        <th data-sort="admin" scope="col">用户类型</th>
                        <th data-sort="status" scope="col">状态</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                        <td data-id="{{ user.user_id }}">{{ user.user_id }}</td>
                        <td>{{ user.username }}</td>
                        <td>{{ user.full_name }}</td>
                        <td>{{ user.email }}</td>
                        <td>{{ user.phone }}</td>
                        <td data-date="{{ user.create_time.strftime('%Y%m%d%H%M%S') if user.create_time else '' }}">
                            {{ user.create_time.strftime('%Y-%m-%d %H:%M:%S') if user.create_time else '未知' }}
                        </td>
                        <td data-admin="{{ user.is_admin|int }}">
                            {% if user.is_admin %}
                            <span class="badge bg-danger">管理员</span>
                            {% else %}
                            <span class="badge bg-info">普通用户</span>
                            {% endif %}
                        </td>
                        <td data-status="1">
                            <span class="badge bg-success">正常</span>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a href="{{ url_for('user.detail', user_id=user.user_id) }}" class="btn btn-sm btn-info" title="查看详情">
                                    <i class="fas fa-info-circle"></i>
                                </a>
                                <a href="{{ url_for('user.edit', user_id=user.user_id) }}" class="btn btn-sm btn-primary" title="编辑用户">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <a href="{{ url_for('user.toggle_status', user_id=user.user_id) }}" class="btn btn-sm btn-secondary" title="当前数据库不支持此功能">
                                    <i class="fas fa-user-slash"></i>
                                </a>
                                <a href="{{ url_for('user.delete', user_id=user.user_id) }}" class="btn btn-sm btn-danger btn-delete" title="删除用户">
                                    <i class="fas fa-trash"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="9" class="text-center py-4">
                            <div class="text-muted">
                                <i class="fas fa-users fa-3x mb-3"></i>
                                <p>暂无用户数据</p>
                                <a href="{{ url_for('user.add') }}" class="btn btn-primary btn-sm">
                                    <i class="fas fa-user-plus me-1"></i>添加用户
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
